<template>
    <!--练习统计-->
    <view class="practiceUser flex flex-column">
        <view class="table f_1 flex flex-column" v-if="sortList.length !== 0">
            <scroll-view scroll-y style="height: 100%" lower-threshold="60" @scrolltolower="scrolltolower"
                class="list-wrapper">
                <view class="table-header flex flex-row">
                    <text style="width:120px">编号</text>
                    <text class="f_1">姓名</text>
                    <view style="width: 70px" class="flex item-center" @click="sortChange">
                        <view>{{ practiceType == 2 ? '正确率' : '成绩' }}</view>
                        <view style="margin-left: 4px" v-if="practiceType != 2">
                            <u-icon name="arrow-up-fill" :color="arrowUpColor" size="8"></u-icon>
                            <u-icon name="arrow-down-fill" :color="arrowDownColor" size="8"></u-icon>
                        </view>
                    </view>
                </view>
                <view class="table-body">
                    <view v-for="(item, index) in sortList" :key="index" class="flex flex-row row item-center"
                        @click="rowClick(item, index)">
                        <view style="width: 120px" v-if="index < 3" class="icon">
                            <image
                                :src="'https://qiniu-bjjrzy.bjjrzy.com/bjupi/practice/cognPractice/improve/' + (index + 1) + '-icon.png'" />
                        </view>
                        <view style="width: 120px" v-else>
                            <text style="margin-left: 17px">{{ index + 1 }}</text>
                        </view>
                        <view class="f_1">{{ item.nickName }}</view>
                        <view style="width: 70px" class="flex flex-row item-center between">
                            <text>{{ practiceType == 2 ? `${item.correctRate}%` : item.scoreInt }}</text>
                            <u-icon name="arrow-right" color="#999999" size="14"></u-icon>
                        </view>
                    </view>
                </view>
            </scroll-view>
        </view>
        <Empty v-else></Empty>
    </view>
</template>

<script>
import Table from "@/improve/components/Table/Table.vue";
import Empty from "@/improve/components/common/Empty.vue";

export default {
    name: "UserPerformance",
    components: { Table, Empty },
    props: {
        dataSource: {
            type: Array,
            default: () => []
        },
        upgPracticeJoinUuid: String,
        practiceType: String,
    },
    data() {
        return {
            upgPracticeUuid: "",
            detail: {},
            date: "",
            list: [],
            scoreSort: null, // 0:升序 1:降序
        }
    },
    computed: {
        statisticalList() {
            return this.dataSource ? this.dataSource : this.list
        },
        arrowUpColor() {
            return this.scoreSort === 0 ? 'green' : '#999'
        },
        arrowDownColor() {
            return this.scoreSort === 1 ? 'green' : '#999'
        },
        sortList() {
            if (this.scoreSort === 0) {
                return this.statisticalList.sort((a, b) => {
                    return a.scoreInt - b.scoreInt
                })
            } else if (this.scoreSort === 1) {
                return this.statisticalList.sort((a, b) => {
                    return b.scoreInt - a.scoreInt
                })
            } else {
                return this.statisticalList
            }
        }
    },
    methods: {
        sortChange() {
            switch (this.scoreSort) {
                case null:
                    this.scoreSort = 0;
                    break;
                case 0:
                    this.scoreSort = 1;
                    break;
                case 1:
                    this.scoreSort = null;
                    break;
                default:
                    this.scoreSort = null
                    break;

            }

            this.$emit('sortChange')
        },
        rowClick(item, index) {
            uni.navigateTo({
                url: `/improve/join/scoreResults/record?bhCheckUuid=${item.bhCheckUuid}&practiceUuid=${item.practiceUuid}&checkIndex=${index}&upgPracticeJoinUuid=${this.upgPracticeJoinUuid}&practiceType=${this.practiceType}`,
            })
        },
        scrolltolower() {

        }
    },
}
</script>

<style scoped lang="scss">
.practiceUser {
    max-height: 100vh;
    width: 100vw;
    // padding-bottom: calc(20px + env(safe-area-inset-bottom));

    .line {
        width: 100%;
        background-color: #F5F5F5;
    }

    .table {
        margin-top: 10px;
        background-color: #FFFFFF;
        padding-bottom: calc(90px + env(safe-area-inset-bottom));

        .table-header {
            padding: 18px 20px;
            font-size: 28rpx;
            color: #999999;
        }

        .table-body {
            .row {
                padding: 18px 20px;
                font-size: 32rpx;
                color: #333333;
                //border-bottom: solid 1px #F2F2F2;
            }

            .row:nth-child(-n+3) {
                padding: 8px 20px;
            }

            .icon {
                image {
                    width: 44px;
                    height: 36px;
                }
            }

        }
    }

    .btn-item {
        padding-top: 20px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        position: fixed;
        background-color: #FFFFFF;
        box-shadow: 1px 1px 4px 2px rgba(0, 0, 0, 0.12);
        bottom: 0;
        width: 100%;
        z-index: 99;

        .btn {
            background-color: #37B874;
            border-radius: 24rpx;
            width: calc(100% - 40px);
            height: 90rpx;
            text-align: center;
            line-height: 90rpx;
            font-size: 32rpx;
            color: #FFFFFF;
            margin-left: 20px;
        }
    }
}
</style>